//
//  WmcEditBrandChangeLocationCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/6/13.
//

import UIKit

extension WmcEditBrandChangeLocationCell {
    class Model {
        // Lifecycle

        init(type: WmcWatermarkOptionModel.Brand.LocationType,
             isSelect: Bool)
        {
            self.type = type
            self.isSelect = isSelect
        }

        // Internal

        var type: WmcWatermarkOptionModel.Brand.LocationType = .followWatermark
        var isSelect: Bool = false
    }
}

// MARK: - [WmcEditBrandChangeLocationCell]

class WmcEditBrandChangeLocationCell: WmcBaseCollectionCell {
    lazy var backgroudView: UIView = {
        let view = UIView()
        view.layer.cornerRadius = 8
        view.layer.masksToBounds = true
        return view
    }()

    lazy var brandLabel: UILabel = {
        let label = UILabel.YP.Create(text: "品牌图",
                                      font: 11.yp.uiFont(weight: .bold),
                                      color: UIColor.white,
                                      alignment: .center)
        label.backgroundColor = .wmc_grayH5_606066
        return label
    }()

    lazy var lineView1: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_lineColor
        return view
    }()

    lazy var lineView2: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_lineColor
        return view
    }()

    override func makeUI() {
        addSubview(backgroudView)
        backgroudView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(-30)
        }

        backgroudView.addSubview(brandLabel)
        
        backgroudView.addSubview(lineView1)
        lineView1.snp.makeConstraints { make in
            make.left.equalTo(8)
            make.bottom.equalTo(-8)
            make.size.equalTo(CGSize(width: 40, height: 5))
        }

        backgroudView.addSubview(lineView2)
        lineView2.snp.makeConstraints { make in
            make.left.equalTo(8)
            make.bottom.equalTo(lineView1.snp.top).offset(-5)
            make.size.equalTo(CGSize(width: 40, height: 5))
        }


        titleLabel.textAlignment = .center
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(backgroudView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
    }

    func configModel(_ model: Model) {
        titleLabel.text = model.type.info.title

        brandLabel.snp.remakeConstraints { make in
            make.size.equalTo(CGSize(width: 40, height: 20))

            switch model.type {
            case .followWatermark:
                make.left.equalTo(8)
                make.bottom.equalTo(lineView2.snp.top).offset(-5)

            case .topLeft:
                make.left.top.equalTo(8)
            case .topRight:
                make.top.equalTo(8)
                make.right.equalTo(-8)
            case .center:
                make.center.equalToSuperview()
            case .bottomLeft:
                make.left.equalTo(8)
                make.bottom.equalTo(-8)
            case .bottomRight:
                make.bottom.right.equalTo(-8)
            }
        }

        if model.isSelect {
            backgroudView.layer.borderColor = UIColor.wmc_mainTheme.cgColor
            backgroudView.layer.borderWidth = 1
            backgroudView.backgroundColor = .wmc_mainTheme.yp.alpha(0.15)

            titleLabel.textColor = .wmc_mainTheme
            titleLabel.font = 14.yp.uiFont(weight: .medium)
        } else {
            backgroudView.layer.borderColor = nil
            backgroudView.layer.borderWidth = 0
            backgroudView.backgroundColor = .wmc_grayH19_F5F5F5

            titleLabel.textColor = .wmc_grayH2_323233
            titleLabel.font = 14.yp.uiFont
        }
    }
}
